home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / ACORNUSERS / EMULATOR / BABE / !Babe / emu (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1998-03-27  |  27KB  |  675 lines

  1.  Project commenced 10/1/98
  2. Initialise_Emu
  3.  Assign variables
  4.  set up emu mode of operation   Display
  5.  1= normal                         y
  6.  2= stepped                        y
  7.  3= realistic time                 y
  8.  4= fast until cycle X             y
  9.  mode%=1
  10.  xcycle%=10
  11. Fa=5      :
  12.  accumulator                    SSEM should it be??????
  13. 2c=6      :
  14.  control instruction (CI)       ARM
  15. 3p=7      :
  16.  present instruction (PI)       SSEM
  17. y=8      :
  18.  loop counter
  19. 3s=9      :
  20.  store memory                   SSEM
  21. 2cycle=10 :
  22.  cycle counter                  ARM
  23.  Problem:
  24.  For ARM chip, MSB is bit 0
  25.  For SSEM MSB is bit 31
  26.  INPUT "Enter object code filename: "; file$
  27.  file$="mem:$.obj"
  28. !Axalign%=7 :
  29.  number of 8 pixels to shift display to the right
  30. yalign%=5
  31. Assemble
  32.  PROCLoadObjectFile(file$)  :REM must load after assembling
  33.  PROCSaveCode("mem:$.BabyCode")
  34.  CALL start
  35. Assemble
  36.  pass%=0 
  37. P%=code%
  38. [OPT pass%
  39. .start
  40. 2'      STMFD       R13!,{R0-R12,R14}
  41. 3@      Swi         256+22                  ;
  42.  22 changes mode
  43. 49      Swi         256+28                  ;to mode 28
  44. 5E      Swi         "OS_RemoveCursors"      ;remove flashing cursor
  45. 6!      Adr         R0,_screen%
  46. 7!      Adr         R1,_screen%
  47. 8H      Swi         "OS_ReadVduVariables"   ;get screen memory address
  48. :L      Adr         s,_store                ;setup pointer to store memory
  49. ;       B           initialise
  50. ._store
  51. >I;32*32 bit lines, kept in this form to allow easy poking of the store
  52. ?M;lines numbered 0-31, bits numbered 0-31 from left to right, bit 0 is LSB
  53. @E                  EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0
  54. AE                  EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0
  55. BE                  EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0
  56. CE                  EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0:EQUD0
  57. ._starttime       EQUD 0
  58. G#._version         :=v$:=0:ALIGN
  59. .initialise
  60.       
  61. P,      Swi         "OS_ReadMonotonicTime"
  62. QG      Str         R0,_starttime                 ;save time at start
  63. S9      Mov         c,#0                    ;set c to 0
  64. T9      Mov         a,#0                    ;set a to 0
  65. U9      Mov         p,#0                    ;set p to 0
  66. V=      Mov         cycle,#0                ;set cycle to 0
  67.       BL          display
  68. .fetchexecute
  69. Y8      ;in accordance with SSEM, c always starts as 1
  70. Z:      Add         c,c,#1                  ;increment c
  71. [$      Add         cycle,cycle,#1
  72. ]9      ;must loop CI round if >31   ie. 
  73.  c>31 
  74.  c=-31
  75.       Cmp         c,#31
  76.       SubGt       c,c,#31
  77.       ;fetch instruction
  78. bL      Mov         R0,c,ASL #2             ;c*4 to get real instr address
  79. cJ                                          ;ie. points to word in store
  80. d@      Ldr         p,[s,R0]                ;load p from store
  81. f?      ;get actline by masking out all bits except 0,1,2,3,4
  82. g)      ;put result in R1 to pass to fn
  83. h=      And         R1,p,#%11111000000000000000000000000000
  84. iM      ;
  85. E actline could be reversed before passing to fn for shorter code
  86. jN      ;but then CMP & STP don't use actline, so pass it 'as is' for speed.
  87. lF      ;get function number by masking out all bits except 13,14,15
  88. m=      And         R0,p,#%00000000000001110000000000000000
  89. o2      ;shift right to get ARM number (MSB 1st)
  90. pP      ;but only by 14 in order that fn number points to a word for jumptable
  91. qG      ;ie. now looks like %000000000000000000000000000xyz00 for ARM
  92. rF      ;on SSEB would be taken as %xyz00000000000000000000000000000
  93. tM      Add         PC,PC,R0,ASR #14        ;jump to position in jump table
  94. uF      Mov         R0,R0                   ;NoOp to allow jumptable
  95. .jumptable
  96. w7      ;NB- since SSEB is LSB 1st and ARM is MSB 1st
  97. x0      ;the 
  98.  table is not in 
  99.  number order.
  100. yI      ;It is in the order of the MSB 1st interpretation of the binary
  101. zF      ;don't use BL as fn will B back to endoftable at end of code
  102. {4      B           jmp_fn                  ;000 0
  103. |4      B           sub_fn                  ;001 4
  104. }4      B           ldn_fn                  ;010 2
  105. ~4      B           cmp_fn                  ;011 6
  106. 4      B           jrp_fn                  ;100 1
  107. O      B           sb5_fn                  ;101 5 (fn 5 is the same as fn 4)
  108. 4      B           sto_fn                  ;110 3
  109. 4      B           stp_fn                  ;111 7
  110. .endoftable
  111. @                                           ;display CI and 
  112.       Ldr         R0,_mode%
  113.       Cmp         R0,#0
  114. D      BLNe        draw_ci                  ;as these alter after
  115. D      BLNe        draw_pi                  ;every fetch execute!
  116. J      Swi         256+31                  ;
  117.  31 (position text cursor)
  118.       Swi         256+0
  119.       Swi         256+37
  120. %      Adr         R0,_cyclestring
  121. !      Swi         "OS_Write0"
  122.       Mov         R0,cycle
  123. #      BL          Print32BitDec
  124.       Mov         R0,#121
  125. 7      Mov         R1,#81 
  126.  &80       ;keycode for S
  127.       Swi         "OS_Byte"
  128.       Cmp         R1,#&FF
  129.        BLEq        screenshot
  130.       Ldr         R0,_stop
  131.       Cmp         R0,#1
  132. !      AdrEq       R0,_stopset
  133. "      SwiEq       "OS_NewLine"
  134. !      SwiEq       "OS_Write0"
  135. "      SwiEq       "OS_NewLine"
  136. !      BEq         end_program
  137. 3      ;check for stepped mode wait for keypress
  138.       Ldr         R0,_mode%
  139.       Cmp         R0,#4
  140. !      LdrEq       R1,_xcycle%
  141.       CmpEq       cycle,R1
  142.       MovEq       R0,#2
  143.       StrEq       R0,_mode%
  144.       Cmp         R0,#2
  145. "      SwiEq       "OS_NewLine"
  146. %      AdrEq       R0,_pressanykey
  147. !      SwiEq       "OS_Write0"
  148.        SwiEq       "OS_ReadC"
  149.       ;check for escape
  150. R      ;Swi         "OS_ReadEscapeState"    ;sets (C)arry flag if escape presed
  151. G      ;BCC         fetchexecute            ;if not escape then loop
  152.       Mov         R0,#121
  153. #      Mov         R1,#112 
  154. F      Swi         "OS_Byte"                  ;check for escape key
  155.       Cmp         R1,#&FF
  156. "      BNe         fetchexecute
  157. .end_program
  158. &      ;print timer and end program
  159. $      Adr         R0,_timestring
  160. !      Swi         "OS_Write0"
  161. ,      Swi         "OS_ReadMonotonicTime"
  162. #      Ldr         R1,_starttime
  163.       Sub         R0,R0,R1
  164. #      BL          Print32BitDec
  165. "      Swi         "OS_NewLine"
  166. =      LDMFD       R13!,{R0-R12,PC}^       ; ==
  167.  PROGRAM==
  168. ._mode%
  169. @      EQUD        mode%                   ;mode of operation
  170. ._xcycle%
  171. Q      EQUD        xcycle%                  ;go normal until at this no. cycle
  172.  ;display all items initially
  173. .display
  174. '      STMFD       R13!,{R0-R12,R14}
  175. I      ;display text before others so that 
  176.  31 does not affect layout
  177. !      Adr         R0,_version
  178. >      Swi         "OS_Write0"             ;display version
  179. "      Swi         "OS_NewLine"
  180. "      Adr         R0,_cistring
  181. !      Swi         "OS_Write0"
  182. "      Adr         R0,_pistring
  183. !      Swi         "OS_Write0"
  184. "      Adr         R0,_acstring
  185. !      Swi         "OS_Write0"
  186. %      Adr         R0,_storestring
  187. !      Swi         "OS_Write0"
  188.        ;number lines in store
  189. R      Mov         R1,#0                   ;setup counter and number to display
  190. .display_storenums
  191. G      Swi         256+31                  ;
  192.  31 set text cursor pos
  193. 8      Swi         256+xalign%-3           ;set x pos
  194. 7      Add         R0,R1,#yalign%          ;set ypos
  195. 6      Swi         "OS_WriteC"             ;do ypos
  196. H      Mov         R0,R1                   ;move counter for printing
  197. =      BL          Print32BitDec           ;print line num
  198. 8      Swi         "OS_NewLine"            ;next line
  199. E      Add         R1,R1,#1                ;inc counter and number
  200. =      Cmp         R1,#32                  ;at end of loop
  201. <      BLt         display_storenums       ;if not branch
  202. +      ;end of store line number display
  203.       BL          draw_ci
  204.       BL          draw_pi
  205. #      BL          draw_ac      
  206. B      Adr         R9,_store               ;setup store address
  207. H      ;no point in waiting for VSync when only executed occasionally
  208.       ;Mov         R0,#19
  209. <      ;Swi         "OS_Byte"               ;
  210.  for VSync
  211.       Mov         R2,#0
  212. .displaystore_loop%
  213. C      ;this should really be optimised to work backwards rather
  214. 0      ;than having to reverse the input line
  215. G      Mov         R8,R2,ASL#2             ;y*4 to get addr in store
  216. N      Ldr         R1,[s,R8]               ;get line into R1 for conversion
  217. B      BL          Reverse32Bit            ;reverse SSEM to ARM
  218. ;      Add         R1,R2,#yalign%          ;add y offset
  219.                 
  220. 7      BL          drawline%               ;drawline
  221. .      ;R0 is set to number to disp already
  222. H      Mov         R3,R0                   ;temp store num to display
  223. C      Swi         256+31                  ;
  224.  31 set text cursor
  225. 8      Swi         256+31+xalign%+2        ;set x pos
  226. 8      Mov         R0,R1                   ;set y pos
  227. 7      Swi         "OS_WriteC"             ;do y pos
  228. H      Mov         R0,R3                   ;get num for display      
  229. :      BL          Print32BitDec           ;display num
  230.       Mov         R1,R3
  231. "      BL          Reverse32Bit
  232. ;      Add         R1,R2,#yalign%          ;add y offset
  233.       BL          disasm
  234.       
  235. >      ;R0 and R1 should already be set to number & y pos !
  236. <      ;Add         R1,R2,#yalign%          ;add y offset
  237.       ;Mov         R0,R3
  238.       
  239.     ?      Add         R2,R2,#1                ;inc line counter
  240. ?      Cmp         R2,#32                  ;test end of loop
  241. ?      BLt         displaystore_loop%      ;if not loop back
  242. /   ;print cycle counter                    
  243. J      Swi         256+31                  ;
  244.  31 (position text cursor)
  245.       Swi         256+0
  246.       Swi         256+37
  247. %      Adr         R0,_cyclestring
  248. !      Swi         "OS_Write0"
  249.       Mov         R0,cycle
  250. #      BL          Print32BitDec
  251. 4      LDMFD       R13!,{R0-R12,PC}^       ;leave
  252. .disasm
  253. 7      ;R0         line to disassemble in SSEM order
  254. +      ;R1         ypos to display it at
  255. '      STMFD       R13!,{R0-R12,R14}
  256. H      Mov         R3,R0                   ;temp store num to display
  257.       
  258. !C      Swi         256+31                  ;
  259.  31 set text cursor
  260. "8      Swi         256+31+xalign%+2+14     ;set x pos
  261. #8      Mov         R0,R1                   ;set y pos
  262. $7      Swi         "OS_WriteC"             ;do y pos
  263.             
  264. &I      And         R0,R3,#%00000000000001110000000000000000    ;get fn
  265. (M      Add         PC,PC,R0,ASR #13        ;jump to position in jump table
  266. )F      Mov         R0,R0                   ;NoOp to allow jumptable
  267. .dis_jumptable
  268. +7      ;NB- since SSEB is LSB 1st and ARM is MSB 1st
  269. ,0      ;the 
  270.  table is not in 
  271.  number order.
  272. -I      ;It is in the order of the MSB 1st interpretation of the binary
  273. .F      ;don't use BL as fn will B back to endoftable at end of code
  274.       Adr         R0,_fn0
  275. 0$      B           dis_endoftable
  276.       Adr         R0,_fn4
  277. 2$      B           dis_endoftable
  278.       Adr         R0,_fn2
  279. 4$      B           dis_endoftable
  280.       Adr         R0,_fn6
  281. 6$      B           dis_endoftable
  282.       Adr         R0,_fn1
  283. 8$      B           dis_endoftable
  284.       Adr         R0,_fn5
  285. :$      B           dis_endoftable
  286.       Adr         R0,_fn3
  287. <$      B           dis_endoftable
  288.       Adr         R0,_fn7
  289. .dis_endoftable
  290. ?!      Swi         "OS_Write0"
  291. A       ;Adr         R0,spaces
  292.       Mov         R0,#
  293. C!      Swi         "OS_WriteC"
  294. EM      And         R1,R3,#%11111000000000000000000000000000   ;get actline
  295. FM      BL          Reverse32Bit                               ;SSEM -> ARM
  296. GO      BL          Print32BitDec                              ;print actline
  297. IQ      ;Adr         R0,spaces                                  ;display spaces
  298. JO      Mov         R0,#
  299. " "                          ;remove trailing digits
  300. K!      Swi         "OS_WriteC"
  301.             
  302. M4      LDMFD       R13!,{R0-R12,PC}^       ;leave
  303. Q ._fn0             :="jmp":=0
  304. R ._fn1             :="jrp":=0
  305. S ._fn2             :="ldn":=0
  306. T ._fn3             :="sto":=0
  307. U ._fn4             :="sub":=0
  308. V ._fn5             :="sb5":=0
  309. W ._fn6             :="cmp":=0
  310. X&._fn7             :="stp":=0:ALIGN
  311. ._screen%
  312. [#                  Equd      148
  313. \"                  Equd      -1
  314. bR;================================= Functions =================================
  315. cG;Note- act line is passed to all fns as MSB 1st (SSEB number) in R1
  316. .jmp_fn
  317. ;000 0
  318. g&;copy content of storeline into CI
  319. iJ      BL          Reverse32Bit            ;reverse actline to ARM form
  320. jM      Mov         R0,R0,ASL #2            ;actline*4 to get addr in store
  321. kC      Ldr         R1,[s,R0]               ;get num to copy to c
  322. lF      BL          Reverse32Bit            ;reverse num to ARM form
  323. m;      Mov         c,R0                    ;put num in c
  324. nK      B           endoftable              ;return to fetch-execute loop
  325. .jrp_fn
  326. ;100 1
  327. r#;add content of storeline to CI
  328. tJ      BL          Reverse32Bit            ;reverse actline to ARM form
  329. uM      Mov         R0,R0,ASL #2            ;actline*4 to get addr in store
  330. vB      Ldr         R1,[s,R0]               ;get num to add to c
  331. wR      BL          Reverse32Bit            ;reverse num to add to c to ARM form
  332. x;      Add         c,c,R0                  ;add num to c
  333. yK      B           endoftable              ;return to fetch-execute loop
  334. .ldn_fn
  335. ;010 2
  336. }5;copy content of storeline negated to accumulator
  337. J      BL          Reverse32Bit            ;reverse actline to ARM form
  338. M      Mov         R2,R0,ASL #2            ;actline*4 to get addr in store
  339. N      Ldr         R1,[s,R2]               ;get num to load as neg into acc
  340. F      BL          Reverse32Bit            ;reverse num to ARM form
  341. F      Rsb         R1,R0,#0                ;R1=0-num (make num -ve)
  342. G      BL          Reverse32Bit            ;reverse num to SSEB form
  343. J      Mov         a,R0                    ;store number in accumulator
  344.       BL          draw_ac
  345. K      B           endoftable              ;return to fetch-execute loop
  346. .sto_fn
  347. ;110 3
  348. +;copy content of accumulator into store
  349. J      BL          Reverse32Bit            ;reverse actline to ARM form
  350. M      Mov         R1,R0,LSL #2            ;actline*4 to get addr in store
  351. H      Str         a,[s,R1]                ;copy accumulator to store
  352. 'MOV r3,r1       ; preserve line no.
  353. MOV r1,a
  354. BL Reverse32Bit ; into r0
  355. L;Mov         R0,a                    ;display AC since identical to line
  356. D      Mov         R1,R3,ASR #2            ;get actline val again
  357. ;      Add         R1,R1,#yalign%          ;add y offset
  358. H      BL          drawline%               ;draw in LEDs the new line
  359. 1      ;R0 is already set to number to display
  360. H      Mov         R3,R0                   ;temp store num to display
  361. C      Swi         256+31                  ;
  362.  31 set text cursor
  363. 8      Swi         256+31+xalign%+2        ;set x pos
  364. 8      Mov         R0,R1                   ;set y pos
  365. 7      Swi         "OS_WriteC"             ;do y pos
  366. B      Mov         R0,R3                   ;get num for display
  367. :      BL          Print32BitDec           ;display num
  368. *      ;convert back to SSEM for disasm
  369.       Mov         R1,R3
  370. "      BL          Reverse32Bit
  371. ;      Add         R1,R2,#yalign%          ;add y offset
  372.       BL          disasm
  373.       
  374. K      B           endoftable              ;return to fetch-execute loop
  375. .sub_fn
  376. ;001 4
  377. .sb5_fn
  378. ;101 5
  379. 3;subtract content of storeline from accumulator
  380. *      ;YUCK! Major optimisation needed
  381. J      BL          Reverse32Bit            ;reverse actline to ARM form
  382. M      Mov         R2,R0,ASL #2            ;actline*4 to get addr in store
  383. F      Ldr         R1,[s,R2]               ;get num to sub from acc
  384. F      BL          Reverse32Bit            ;reverse num to ARM form
  385. =      Mov         R4,R0                   ;move num to R4
  386. D      Mov         R1,a                    ;move acc for reversal
  387. F      BL          Reverse32Bit            ;reverse acc to ARM form
  388. E      Sub         R1,R0,R4                ;R1=R0-R4 to get result
  389. J      BL          Reverse32Bit            ;reverse result to SSEM form
  390. J      Mov         a,R0                    ;store result in accumulator
  391.       BL          draw_ac
  392. K      B           endoftable              ;return to fetch-execute loop
  393. .cmp_fn
  394. ;011 6
  395. 8;skip next instruction if content of accumulator < 0
  396. T      And         R0,a,#%00000000000000000000000000000001 ;mask all but sign bit
  397. J      Cmp         R0,#%00000000000000000000000000000001 ;test sign bit
  398. O      AddEq       c,c,#1                  ;if -ve bit set then increment CI
  399. K      B           endoftable              ;return to fetch-execute loop
  400. .stp_fn
  401. ;111 7
  402.       Mov         R0,#1
  403. A      Str         R0,_stop                ;set stop flag to 1
  404. K      B           endoftable              ;return to fetch-execute loop
  405.       
  406. *;area to load sprites to on assembling
  407. ._sprites%
  408.       EQUD     sprites%
  409.          
  410. A._at_line         :=13:=10:="At store line number: ":=0:ALIGN
  411. 0._dummy           :="dummy display":=0:ALIGN
  412. %._32bit           :=
  413. 0):ALIGN
  414. 0._cistring        :="C I: ":=13:=10:=0:ALIGN
  415. 0._pistring        :="P I: ":=13:=10:=0:ALIGN
  416. 0._acstring        :="ACC: ":=13:=10:=0:ALIGN
  417. 2._storestring     :="Store: ":=13:=10:=0:ALIGN
  418. )._stopstring      :="STOP: ":=0:ALIGN
  419. *._cyclestring     :="Cycle: ":=0:ALIGN
  420. .._timestring      :="Time (cs): ":=0:ALIGN
  421. E._stopset         :="The STP function has been executed":=0:ALIGN
  422. E._pressanykey     :="Press any key to continue.":=13:=10:=0:ALIGN
  423. ;on entry
  424. 7      ;R0 contains word to display  (ARM version!!)
  425.       ;R1 is the y pos
  426. .drawline%
  427. &      STMFD       R13!,{R0-R8,R14}
  428. 6      Mov         R3,#(0+xalign%)   ;starting xpos
  429. @      Ldr         R6,_screen%       ;get base screen address
  430. @      Ldr         R7,_sprites%      ;get base sprite address
  431.       
  432. .drawline_loop%
  433. !      ;need to preserve R0,R1
  434.       ;R0 word to display
  435.       ;R1 ypos
  436.       ;R2 temp
  437.       ;R3 xcount
  438. !      ;R4 screen address temp
  439. !      ;R5 sprite address temp
  440. %      ;R6 screen address perm  Ra
  441. %      ;R7 sprite address perm  Rb
  442.       ;R8 temp
  443. >      Mov         R4,R6                   ;get screen addr
  444. H      Add         R4,R4,R3,Lsl#3          ;mul by 8 to account for x
  445. N      Add         R4,R4,R1,Lsl#12         ;mul by (8*640) to account for y
  446. ;      Add         R4,R4,R1,Lsl#10         ;and y offset
  447. ?      Mov         R5,R7                   ;get sprites addr
  448. K      Sub         R8,R3,#xalign%          ;subtract align for bit shift
  449. F      Mov         R8,R0,Asr R8            ;put bit needed to bit 0
  450. A      And         R2,R8,#1                ;mask all but bit 0
  451. I      Add         R5,R5,R2,Lsl#6          ;mul by 64 (size of sprite)
  452.       ;plot sprite
  453. !      LdmIa       R5!,{R2,R8}
  454.        StmIa       R4,{R2,R8}
  455.            Add         R4,R4,#640
  456. !      LdmIa       R5!,{R2,R8}
  457.        StmIa       R4,{R2,R8}
  458.        Add         R4,R4,#640
  459. !      LdmIa       R5!,{R2,R8}
  460.        StmIa       R4,{R2,R8}
  461.        Add         R4,R4,#640
  462. !      LdmIa       R5!,{R2,R8}
  463.        StmIa       R4,{R2,R8}
  464.        Add         R4,R4,#640
  465. !      LdmIa       R5!,{R2,R8}
  466.        StmIa       R4,{R2,R8}
  467.        Add         R4,R4,#640
  468. !      LdmIa       R5!,{R2,R8}
  469.        StmIa       R4,{R2,R8}
  470.        Add         R4,R4,#640
  471. !      LdmIa       R5!,{R2,R8}
  472.        StmIa       R4,{R2,R8}
  473.        Add         R4,R4,#640
  474. !      LdmIa       R5!,{R2,R8}
  475.        StmIa       R4,{R2,R8}
  476.        Add         R4,R4,#640
  477.       ;end of sprite plot
  478.  >      Add         R3,R3,#1                ;inc bit counter
  479. !9      Cmp         R3,#(32+xalign%)        ;check loop
  480. "F      BLt         drawline_loop%          ;loop back if unfinished
  481. #3      LDMFD       R13!,{R0-R8,PC}^       ;leave
  482. .draw_ci
  483. %&      STMFD       R13!,{R0-R1,R14}
  484. &&      ;display control instruction
  485. '<      ;Mov         R0,#1                         ;line=1
  486. (       ;BL          clearline
  487.       Mov         R0,c
  488. *N      Swi         256+31                        ;
  489.  31 position text cursor
  490. +@      Swi         256+32+1+xalign%              ;x=31+xalign
  491. ,8      Swi         256+1                         ;y=1
  492. -A      BL          Print32BitDec                 ;print number
  493. .H      Mov         R1,c                          ;copy c for reversal
  494. /(      BL          Reverse32Bit      
  495. 0;      Mov         R1,#1                         ;line 1
  496. 1=      BL          drawline%                     ;drawline
  497.       
  498. 33      LDMFD       R13!,{R0-R1,PC}^       ;leave
  499. .draw_pi
  500. 6&      STMFD       R13!,{R0-R1,R14}
  501. 7&      ;display present instruction
  502.       Mov         R1,p
  503. 9"      BL          Reverse32Bit
  504. :5      Mov         R1,#2                   ;line 2
  505. ;7      BL          drawline%               ;drawline
  506.       Mov         R0,p
  507.       Mov         R1,#2
  508.       BL          disasm
  509. ?3      LDMFD       R13!,{R0-R1,PC}^       ;leave
  510. .draw_ac
  511. B&      STMFD       R13!,{R0-R1,R14}
  512.       ;display accumulator
  513. D<      ;Mov         R0,#3                         ;line=1
  514. E       ;BL          clearline
  515. FB      Mov         R1,a                    ;copy a for reversal
  516. G"      BL          Reverse32Bit
  517. H5      Mov         R1,#3                   ;line 3
  518. I7      BL          drawline%               ;drawline
  519. J?      ;since ACC is in SSEM form then need reversed version
  520. KH      Swi         256+31                  ;
  521.  31 position text cursor
  522. L:      Swi         256+32+1+xalign%        ;x=31+xalign
  523. M2      Swi         256+3                   ;y=3
  524. N;      BL          Print32BitDec           ;print number
  525. O4      LDMFD       R13!,{R0-R1,PC}^        ;leave
  526. Q0;store for the SSEM stop lamp 1=lit, 0=unlit
  527. ._stop
  528.                     EQUD 0
  529. U-;----------------------------------------
  530. V-; start of assembler function definitions
  531. X$.Reverse32Bit     
  532. reverse_32bit
  533. Y(.Print32BitBin    
  534. print_32bitBinary
  535. Z).Print32BitDec    
  536. print_32bitDecimal
  537. [-;----------------------------------------
  538. .screenshot
  539. ^&      STMFD       R13!,{R0-R3,R14}
  540. _)      Adr         R0,inputfile_string
  541. `!      Swi         "OS_Write0"
  542. b!      Adr         R0,filename
  543.       Mov         R1,#255
  544.       Mov         R2,#0
  545.       Mov         R3,#255
  546. f#      Swi         "OS_ReadLine"
  547. h'      Swi         256+12         ;
  548. i7      BL          display        ;do full redisplay
  549. k'      Adr         R0,screensave_cli
  550.       Swi         "XOS_CLI"
  551. n4      LDMFD       R13!,{R0-R3,PC}^        ;leave
  552. .inputfile_string
  553. q9      EQUS        "Type in the filename to save as: "
  554.       EQUB        0
  555.       ALIGN
  556. .screensave_cli
  557. v#      EQUS        "SCREENSAVE "
  558. .filename
  559.       EQUS        
  560.       ALIGN
  561. P._advert          :="The Acorn Emulation Page http://www.come.to/emulate":=0
  562.     ALIGN
  563. LoadObjectFile(file$)
  564.  blank store
  565.  x%=0 
  566.       _store!(x%*4)=!zero
  567.    A=
  568. (file$)
  569.    lines$=
  570.    count%=0
  571.       line$=
  572.       
  573.  line$<>"" 
  574.          count%+=1
  575. !         line%=
  576. line$,3,2))
  577. '         instr%=
  578. ("%"+
  579. line$,6,32))
  580. $         _store!(line%*4)=instr%
  581.       
  582.  count%=
  583. (lines$)
  584. SaveCode(savefile$)
  585.  "SAVE "+savefile$+" "+
  586. ~(code%)+" "+
  587. ~(P%)
  588.  "SETTYPE "+savefile$+" &FFD"
  589. Error
  590. $;" at line ";
  591.    IF ERR<>17 THEN CHAIN "Edit:Throwback" ELSE END
  592. ===================================
  593.  Start of assembler functions
  594. ===================================
  595. reverse_32bit
  596. [OPT pass%
  597. ); On entry R1=32bit number to reverse
  598. 2; On exit  R0=The Reversed number R1 unchanged
  599. $;          Flags      - prserved
  600. %;          Other Regs - preserved
  601. %;          Intterupts - unaltered
  602. ;          SVC mode   - Yes
  603. ;          Re-enterant- No
  604.    STMFD      R13!,{R1,R14}
  605.      Mov       R0,R1
  606.      LDR     R1,mask5
  607.      
  608.     R1,R1,R0,LSR #1
  609.      BIC    R0,R0,R1,LSL #1
  610.      
  611. R    R0,R1,R0,LSL #1
  612.      LDR    R1,mask3
  613.      
  614.     R1,R1,R0,LSR #2
  615.      BIC    R0,R0,R1,LSL #2
  616.      
  617. R    R0,R1,R0,LSL #2
  618.      LDR    R1,mask0F
  619.      
  620.     R1,R1,R0,LSR #4
  621.      BIC    R0,R0,R1,LSL #4
  622.      
  623. R    R0,R1,R0,LSL #4
  624.      MOV    R1,#&FF
  625.      ADD    R1,R1,#&FF0000
  626.      
  627.     R1,R1,R0,LSR #8
  628.      BIC    R0,R0,R1,LSL #8
  629.      
  630. R    R0,R1,R0,LSL #8
  631.      MOV    R1,R0,LSR #16
  632.      
  633. R    R0,R1,R0,LSL #16
  634.    LDMFD      R13!,{R1,PC}^
  635. .mask5   DCD   &55555555
  636. .mask3   DCD   &33333333
  637. .mask0F  DCD   &0F0F0F0F
  638.     .zero
  639. (         EQUB 0:EQUB 0:EQUB 0:EQUB 0
  640. ===================================
  641. print_32bitBinary
  642. [OPT pass%
  643. (;purpose - print 32 bit binary in R0
  644. #; on entry R0 = number to print
  645. &      STMFD       R13!,{R0-R2,R14}
  646.       Adr         R1,_32bit
  647.       Mov         R2,#33
  648. @      Swi         "OS_ConvertBinary4"     ;convert to binary
  649. ;      Swi         "OS_Write0"             ;print binary
  650. &      LDMFD       R13!,{R0-R2,PC}^
  651. ===================================
  652. print_32bitDecimal
  653. [OPT pass%
  654. 0;purpose - print signed 32 bit decimal in R0
  655. #; on entry R0 = number to print
  656. &      STMFD       R13!,{R0-R2,R14}
  657.       Adr         R1,_32bit
  658. >      Mov         R2,#12                  ;set buffer size
  659. P      Swi         "OS_ConvertInteger4"   ;convert int>string upto 4294967295
  660. )SWI   "OS_Write0"    ; display number
  661. 0RSB   r2,r2,#12    ; bytes already printed-1
  662. .pad      
  663. CMP   r2,#0
  664. ,SWI 256+32 ; trailing spaces (minimum 1)
  665. SUBGT r2,r2,#1
  666. BGT   pad
  667. K      ;Mov         R2,#
  668. " "             ;add a space onto end of string
  669.       ;StrB        R2,[R1]
  670. F      ;Mov         R2,#0                  ;move null terminator +1
  671. !      ;StrB        R2,[R1,#1]
  672. >      ;Swi         "OS_Write0"             ;display number
  673. &      LDMFD       R13!,{R0-R2,PC}^
  674. ===================================
  675.